package com.lagou;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SortBean implements WritableComparable<SortBean> {

    private Integer id;
    private Integer num;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public SortBean() {
    }

    public SortBean(Integer id, Integer num) {
        this.id = id;
        this.num = num;
    }

    @Override
    public String toString() {
        return id + "\t" + num;
    }
    //排序
    @Override
    public int compareTo(SortBean o) {
        if(this.num > o.num){
            return 1;
        }else if(this.num < o.num){
            return -1;
        }else{
            return 0;
        }
    }
    //序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(id);
        dataOutput.writeInt(num);

    }
    //反序列化方法
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readInt();
        this.num = dataInput.readInt();
    }
}
